package com.dfec.book.controller;

import com.dfec.book.entity.StudentEntity;
import com.dfec.book.service.StudentService;
import com.dfec.book.util.AjaxResult;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tangrg
 * @email 1446232546@qq.com
 * @date 2025-07-2025/7/2 11:06:40
 */
@RestController
@RequestMapping("/student")
@Api(tags = "学生管理")
@ApiSort(2)
public class StudentController {

    @Resource
    private StudentService studentService;


    @PostMapping("/getStudents")
    @ApiOperation("获取学生列表")
    public AjaxResult<List<StudentEntity>> getStudents(@RequestBody StudentEntity student) {
        List<StudentEntity> students = studentService.getStudents(student);
        return AjaxResult.ok().put(students);
    }


    @PostMapping("/addStudent")
    @ApiOperation("添加学生列表")
    public AjaxResult<Boolean> addStudent(@RequestBody @Validated StudentEntity student) {
        Boolean flag = studentService.addStudent(student);
        return AjaxResult.ok().put(flag);
    }



    @PostMapping("/updateStdent")
    @ApiOperation("更新学生列表")
    public AjaxResult<Boolean> updateStdent(@RequestBody StudentEntity student) {
        Boolean flag = studentService.updateStdent(student);
        return AjaxResult.ok().put(flag);
    }

    @PostMapping("/deleteStudent")
    @ApiOperation("删除学生列表")
    public AjaxResult<Boolean> deleteStudent(@RequestBody List<Integer> studentIds) {
        Boolean flag = studentService.deleteStudent(studentIds);
        return AjaxResult.ok().put(flag);
    }

}
